package com.spic.system.controller;

import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.datascope.annotation.DataScope;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import com.spic.system.domain.SysAnnounce;
import com.spic.system.service.ISysAnnounceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 授权公示公告
 * @author 290512
 * @create 2022-06-17 15:17
 */
@RestController
@RequestMapping("/announceAuth")
public class SysAnnounceAuthController extends BaseController
{
    @Autowired
    private ISysAnnounceService sysAnnounceService;

    /**
     * 查询授权公示公告内容列表
     */
    @DataScope(deptAlias = "d", userAlias = "u", menuPath = "system/publicity/announcementAuth/index")
    @PreAuthorize(hasPermi = "system:publicity:announcementAuth:list")
    @GetMapping("/list")
    public TableDataInfo list(SysAnnounce sysAnnounce)
    {
        startPage();
        List<SysAnnounce> list = sysAnnounceService.selectSysAnnounceAuthList(sysAnnounce);
        return getDataTable(list);
    }

    /**
     * 获取授权公示公告内容详细信息
     */
//    @PreAuthorize(hasPermi = "system:announceAuth:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysAnnounceService.selectSysAnnounceAuthById(id));
    }

    /**
     * 修改授权公示公告内容
     */
//    @PreAuthorize(hasPermi = "system:announceAuth:edit")
    @Log(title = "授权公示公告内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAnnounce sysAnnounce)
    {
        sysAnnounceService.updateSysAnnounceAuth(sysAnnounce);
        return AjaxResult.success();
    }

}
